<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: allen.qiang
// +----------------------------------------------------------------------

/**
 * 大数据导出类 mysqlExportHandler
 * @package  htdocs
 * @subpackage  module/base
 * @author   allen.qiang
 * @version 1.0  
 */

class mysqlExportHandler {
    private $dbca;
    public function __construct(&$dbca) {
        $this->dbca = $dbca;
    }
    
    /**
     * 根据sql导出
     *
     * @param unknown_type $sqlStr	查询sql语句
     * @param unknown_type $fields	导出字段
     * @param unknown_type $ip		请求服务器的ip地址
     * @param unknown_type $port	请求服务器的端口
     */
	public function exportReq($sqlStr , $fields , $ip = '127.0.0.1' , $port = CODE_RELEASE_TEST_SERVER_PORT) {
		
		
		$fieldStr = implode("','" , $fields) ;
		$sql_sql  = "SELECT '$fieldStr' " ;
		$sqlStr	  = $sql_sql . ' UNION ALL ' . $sqlStr ;
		
		//sql64位加密
		$e_sql 	 = base64_encode($sqlStr);	
		
		//rpc请求															
		$rpc 	 = new rpc_http();
		$url  	 = "http://$ip:$port/app_innercall/export.php";
				
		//设置url请求的地址									
		$data 	 = array('q' => $e_sql);
		$rpcArr  = $rpc->http_post($url , $data);
		
		//下载数据文件
		if($rpcArr['code'] == 200 && $rpcArr['result']['code'] == 200){
			$fileName = $rpcArr['result']['message'];															//导出的文件名			
			header('Location:' . G_WEBSITE_DOMAINNAME . '/shop/html_cache/' . $fileName);						//下载文件
		}else {
			die(print_r($rpcArr,true));
		}
	}
	
}